const XLSX = require('xlsx');
const path = require('path');

// 创建包含测试数据的Excel文件
const createTestExcel = () => {
  // Dishes数据
  const dishesData = [
    ['dish_sku', 'dish_slug', 'name_zh', 'name_en', 'category', 'base_status', 'description_zh', 'description_en', 'ingredients_zh', 'ingredients_en', 'tags', 'popularity'],
    ['BEEF001', 'beef-noodles', '牛肉面', 'Beef Noodles', '面条类', 'active', '香浓牛肉面', 'Delicious beef noodles', '牛肉,面条,青菜', 'Beef, noodles, vegetables', '热门,推荐', '85'],
    ['CHICKEN002', 'chicken-rice', '鸡肉饭', 'Chicken Rice', '饭类', 'active', '嫩滑鸡肉饭', 'Tender chicken rice', '鸡肉,米饭,酱汁', 'Chicken, rice, sauce', '经典', '90'],
  
  ];

  // Variants数据
  const variantsData = [
    ['dish_sku', 'name_zh', 'variant_code', 'variant_name', 'price', 'compare_at_price', 'is_default', 'stock'],
    ['BEEF001', '小份', 'SMALL', 'Small', '12.80', '15.00', 'true', '50'],
    ['BEEF001', '大份', 'LARGE', 'Large', '16.80', '20.00', 'false', '30'],
    ['CHICKEN002', '标准', 'REGULAR', 'Regular', '10.50', '', 'true', '100'],
  
  ];

  // Options数据
  const optionsData = [
    ['dish_sku', 'name_zh', 'group_code', 'group_name', 'required', 'value_code', 'value_name', 'price_delta'],
    ['BEEF001', '辣度', 'SPICY', 'Spice Level', 'true', 'MILD', 'Mild', '0'],
    ['BEEF001', '辣度', 'SPICY', 'Spice Level', 'true', 'MEDIUM', 'Medium', '0'],
    ['BEEF001', '辣度', 'SPICY', 'Spice Level', 'true', 'HOT', 'Hot', '0'],
    ['BEEF001', '加料', 'EXTRA', 'Extra Toppings', 'false', 'EGG', 'Extra Egg', '2.00'],
    ['CHICKEN002', '饮料', 'DRINK', 'Drink', 'false', 'COKE', 'Coca Cola', '2.50'],
  
  ];

  // 创建工作簿
  const wb = XLSX.utils.book_new();

  // 创建工作表
  const dishesWs = XLSX.utils.aoa_to_sheet(dishesData);
  const variantsWs = XLSX.utils.aoa_to_sheet(variantsData);
  const optionsWs = XLSX.utils.aoa_to_sheet(optionsData);

  // 添加工作表到工作簿
  XLSX.utils.book_append_sheet(wb, dishesWs, 'Dishes');
  XLSX.utils.book_append_sheet(wb, variantsWs, 'Variants');
  XLSX.utils.book_append_sheet(wb, optionsWs, 'Options');

  // 保存文件
  const filePath = '/tmp/test_menu_data.xlsx';
  XLSX.writeFile(wb, filePath);
  console.log(`测试数据文件已创建: ${filePath}`);
  console.log(`文件大小: ${require('fs').statSync(filePath).size} 字节`);
};

// 执行创建
try {
  createTestExcel();
  console.log('✓ 测试数据创建成功');
} catch (error) {
  console.error('✗ 创建测试数据失败:', error.message);
  process.exit(1);
}